package cn.fintecher.pangolin.service.business.repository.jparepository;

import cn.fintecher.pangolin.entity.mysql.AssistCase;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface AssistCaseRepository extends JpaRepository<AssistCase, String>, QuerydslPredicateExecutor<AssistCase> {
    /**
     * 查询管理员委托方
     */
    @Query(value = "select distinct a.principal_id,a.principal_name from assist_case a left join user b on a.assist_collector_id = b.id left join department c on b.depart_id = c.id" +
            " where c.depart_code like concat(:code, '%') and a.assist_status in ('ASSIST_WAIT_ASSIGN','ASSIST_COLLECTING')", nativeQuery = true)
    List<Object[]> findPrincipalByManager(@Param("code") String departCode);

    /**
     * 查询催收员委托方
     */
    @Query(value = "select distinct principal_id,principal_name from assist_case where assist_collector_id = :id  and assist_status in ('ASSIST_WAIT_ASSIGN','ASSIST_COLLECTING')",nativeQuery = true)
    List<Object[]> findPrincipalByCollector(@Param("id") String id);
}
